﻿@{
    ViewBag.Title = "SettingIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script>
    var organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
    $(function () {
        InitialPage();
        GetList();

    });
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        $('.profile-nav').height($(window).height() - 20);
        $('.profile-content').height($(window).height() - 20);
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('.profile-nav').height($(window).height() - 20);
                $('.profile-content').height($(window).height() - 20);
            }, 200);
            e.stopPropagation();
        });
    }
    //侧面切换显示/隐藏
    function profileSwitch(id) {
        $(".profile-content").find('.flag').hide()
        $(".profile-content").find("#" + id).show();
        if (id == 'WorkAudit') {
            GetWorkAuditHtml();
        }
        if (id == 'WorkRole') {
            GetWorkRoleList(); 
        }
    } 


    function changeType(type, code) { 
        $('#RoleId_' + code).html("");
        if (type == 1) { 
            $('#RoleId_' + code).ComboBoxTree({
                url: '../../BaseManage/Post/GetTreeJson',
                id: 'value',
                text: 'text',
                description: '==请选择==',
                allowSearch: true
            });
        }
        if (type == 2) {
            $('#RoleId_' + code).ComboBoxTree({
                url: '../../BaseManage/Role/GetRoleCheckTreeJson',
                id: 'value',
                text: 'text',
                description: '==请选择==',
                allowSearch: true
            });
        }
    }
    function GetWorkRoleList() {
        $.SetForm({
            url: "../../SystemManage/Setting/GetWorkRoleList",
            success: function (data) {
                $("#WorkRoleForm").html(data.Html); 
                $("#JS").html(data.JS);
            }
        });
    }

    function SetCombox(id, type) {
        if (type == 2) {
            $("#" + id).ComboBox({
                url: "../../BaseManage/Role/GetListJson",
                id: "RoleId",
                text: "FullName",
                description: "==请选择==",
                allowSearch: true
            });
        }
        else if (type == 1) {
            $("#" + id).ComboBox({
                url: "../../BaseManage/Post/GetTreeJson?organizeId",
                id: "RoleId",
                text: "FullName",
                description: "==请选择==",
                allowSearch: true
            });
        }
    }


    //单据
    function GetList() {
        $("#AutoBillCodeTable").html("");
        $.ajax({
            url: "../../SystemManage/Setting/GetListHtml",
            type: "get",
            dataType: "json",
            success: function (data) {
                $("#AutoBillCodeTable").append(data.html);
            },
            error: function (e) {
                alert(Error);
            }
        });
    }
    //审批环节
    function GetWorkAuditHtml() {
        $("#WorkAuditTable").html("");
        $.ajax({
            url: "../../SystemManage/Setting/GetWorkAuditHtml",
            type: "get",
            dataType: "json",
            success: function (data) {
                $("#WorkAuditTable").append(data.html);
            },
            error: function (e) {
                alert(Error);
            }
        });
    }

    //保存单据
    function SaveContactPanel(EnCode) {

        var rows = document.getElementById("AutoBillCodeTable").rows.length;
        // var colums = document.getElementById("AutoBillCodeTable").rows[0].cells.length; //获得列数
        //var data = new Array();
        var entity = "";
        for (var i = 0; i < rows - 1; i++) {
            if ($("#AutoBillCodeTable tr:eq(" + i + ") td:eq(0)").html() == EnCode.toString()) {
                var obj = new Object();
                obj.EnCode = EnCode
                obj.FullName = $("#AutoBillCodeTable tr:eq(" + i + ") td:eq(1)").html();
                if ($("#AutoBillCodeTable tr:eq(" + i + ") td:eq(2) input")[0].checked) obj.Mode = 1
                else obj.Mode = 0;
                obj.CodeRuleId = $("#AutoBillCodeTable tr:eq(" + i + ") td:eq(3)")[0].childNodes[0].title;
                if (obj != null) entity = JSON.stringify(obj);
            }
        }
        $.SaveForm({
            url: "../../SystemManage/Setting/SaveAutoBillCode",
            param: { "keyValue": EnCode, "strBillCodeSettingEntity": entity },
            loading: "正在保存数据...",
            success: function () {
                // top.reload();
            }
        })
    }

    function btn_WorkAudit(id) {
        dialogOpen({
            id: "WorkAuditSetting",
            title: '修改工单审核角色',
            url: '../../SystemManage/Setting/WorkAuditSetting?keyValue=' + id,
            width: "1000px",
            height: "750px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }

    function SaveWorkRole(encode) { 
        var RoleId = $("#RoleId_" + encode).attr("data-value");
        if (!!RoleId) {
            var postData = {
                Id: $("#Id_" + encode).text(),
                Name: $("#Name_" + encode).text(),
                EnCode: encode,
                RoleType: $("#WorkRoleForm input[name='RoleType_" + encode + "']:checked ").val(),
                RoleId: RoleId,
                Mode: $("#WorkRoleForm input[name='Mode_" + encode + "']:checked ").val(),
                OrganizeId: $("#OrganizeId_" + encode).attr("data-value"),
            };
            $.ConfirmAjax({
                msg: "注：您确认要进行此操作吗？",
                url: "/SystemManage/Setting/SaveWorkRole",
                param: postData,
                loading: "正在保存数据...",
                success: function () {
                    GetWorkRoleList();
                }
            });
           
        } else {
            dialogMsg('未选授权角色！', 0);
            return false;
        }


    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="profile-nav">
                <ul style="padding-top: 20px;">
                    <li class="active" onclick="profileSwitch('AutoBillCode')">单据自动编码配置</li>
                    <li onclick="profileSwitch('WorkAudit')">工作环节配置</li>
                    <li onclick="profileSwitch('WorkRole')">工作角色配置</li>
                    @*<li onclick="profileSwitch('SafetyVerify')">安全验证</li>
                        <li onclick="profileSwitch('SetLanguage')">语言设置</li>
                          <div class="divide"></div>
                          <li onclick="profileSwitch('SystemLog')">系统日志</li>*@
                </ul>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="profile-content" style="background: #fff;">
                <div id="AutoBillCode" class="flag">
                    <div class="title">
                        单据自动编码配置
                    </div>
                    <table id="AutoBillCodeTable" class="form" style="margin-top: 20px;"></table>
                </div>

                <div id="WorkAudit" class="flag" style="display: none; ">
                    <div class="title">
                        工作环节配置
                    </div>
                    <div style="margin-top: 10px;">
                        <div class="gridPanel">
                            <table id="WorkAuditTable">
                                <tr><td class="formTitle"></td><td class="formValue" colspan="4"></td></tr>
                            </table>
                        </div>
                    </div>
                </div>
                <div id="WorkRole" class="flag" style="display: none;">
                    <div class="title">
                        工作角色配置
                    </div>
                    <table class="form" id="WorkRoleForm" style="margin-top: 20px;"></table>

                </div>
                <div id="JS">

                </div>

                @*<div id="SafetyVerify" class="flag" style="display: none;">
                           <div class="title">
                               安全验证
                           </div>
                       </div>
                       <div id="SetLanguage" class="flag" style="display: none;">
                           <div class="title">
                               语言设置
                           </div>
                    </div>*@
            </div>
        </div>
    </div>
</div>
<style>
    .file {
        position: relative;
        display: inline-block;
        overflow: hidden;
        text-decoration: none;
        text-indent: 0;
        cursor: pointer !important;
    }

        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
            cursor: pointer !important;
        }

        .file:hover {
            text-decoration: none;
            cursor: pointer !important;
        }
</style>